/*
 * Assert.java
 *
 * Created on 2007/12/28 +0900
 *
 * $Revision: 60 $
 * $Date: 2008-12-28 19:27:48 +0000 (Sun, 28 Dec 2008) $
 */

package org.gikolet.framework.util;

/**
 * @author Tetsutaro (latest modification by $Author: tetsutaro.ss $)
 * @version $Revision: 60 $ $Date: 2008-12-28 19:27:48 +0000 (Sun, 28 Dec 2008) $
 */
public final class Assert {
    private Assert() {
    }

    public static void isNull(Object obj) {
	isNull(obj, null);
    }

    public static void isNull(Object obj, String message) {
	if (obj != null) {
	    String msg = "Object is not null.";
	    if (message != null) {
		msg += ": " + message;
	    }
	    throw new AssertException(msg);
	}
    }

    public static void isNotNull(Object obj) {
	isNotNull(obj, null);
    }

    public static void isNotNull(Object obj, String message) {
	if (obj == null) {
	    String msg = "Object is null.";
	    if (message != null) {
		msg += ": " + message;
	    }
	    throw new AssertException(msg);
	}
    }

    public static void isNotEmpty(String str) {
	isNotEmpty(str, null);
    }

    public static void isNotEmpty(String str, String message) {
	if (str.length() == 0) {
	    String msg = "String is empty.";
	    if (message != null) {
		msg += ": " + message;
	    }
	    throw new AssertException(msg);
	}
    }

    public static void fail() {
	fail(null);
    }

    public static void fail(String message) {
	throw new AssertException(message);
    }

    /**
     * @param str
     */
    public static void isNotNullAndEmpty(String str) {
	isNotNullAndEmpty(str, null);
    }

    /**
     * @param str
     * @param message
     */
    public static void isNotNullAndEmpty(String str, String message) {
	isNotNull(str, message);
	isNotEmpty(str, message);
    }

    /**
     * @param b
     */
    public static void isNotTrue(boolean b) {
	isNotTrue(b, null);
    }

    /**
     * @param b
     * @param message
     */
    public static void isNotTrue(boolean b, String message) {
	isFalse(b, message);
    }

    /**
     * @param b
     */
    public static void isTrue(boolean b) {
	isTrue(b, null);
    }

    /**
     * @param b
     * @param message
     */
    public static void isTrue(boolean b, String message) {
	if (!b) {
	    String msg = "boolean is false.";
	    if (message != null) {
		msg += ": " + message;
	    }
	    throw new AssertException(msg);
	}
    }

    /**
     * @param b
     */
    public static void isFalse(boolean b) {
	isFalse(b, null);
    }

    /**
     * @param b
     * @param message
     */
    public static void isFalse(boolean b, String message) {
	if (b) {
	    String msg = "boolean is true.";
	    if (message != null) {
		msg += ": " + message;
	    }
	    throw new AssertException(msg);
	}
    }
}
